from django.utils import simplejson
from django.http import HttpResponse
from qbank.models import quesAns
from qbank.models import dialog
from qbank.models import course

def qa_json(request, dialogId=None):
	qArray = []
	d_id=request.GET.get('dialog_Id')
	qaList = dialog.objects.get(id=d_id).quesans_set
	qArray.append({"Total count":qaList.count()})
	for q in qaList.all():
		mediaPath = ""
		if(q.media):
			mediaPath = q.media.url 
		qArray.append({"id":q.id,"question":q.question,"answer":q.answer, "authorRating":q.authorRating, "qaGroup":q.qaGroup, "groupOrder":q.groupOrder, "authorRating":q.authorRating, "media":mediaPath})
	
	response = HttpResponse(simplejson.dumps(qArray),mimetype='application/json')
	response['Content-Disposition'] = 'filename=QABank.json' 
	return response

def tags(request):
	names = [c.courseCode for c in course.objects.all()]
	response = HttpResponse(simplejson.dumps(names), mimetype='application/json')
	return response
		
